import mockjs from 'mockjs';
import {Request, Response} from 'express';

export default {
  // 支持值为 Object 和 Array
  'GET /api/user/info': (req: Request, res: Response) => {
    const data = mockjs.mock({ id: '@id', name: '@name', age: '@integer(1,100)'});
    setTimeout(() => {
      res.send(data);
      // res.status(401).send('forbidden');
    }, 100);
  },
  'POST /api/user/citys': (req: Request, res: Response) => {
    // 添加跨域请求头
    const data = mockjs.mock({
          'citys|100': [{ name: '@city', 'value|1-100': 50, 'type|0-2': 1 }],
        });
    // console.log(data);
    res.setHeader('Access-Control-Allow-Origin', '*');
    setTimeout(() => {
      res.send(data.citys);
    }, 100 * 5);
  },

  'POST /api/user/roles': mockjs.mock({ id: '@id', age: '@integer(1,100)'}),

  // GET 可忽略
  '/api/users/1': { id: 1 },
};
